package cn.xuqiudong.rpc.protocol.http;

import cn.xuqiudong.rpc.common.util.ExecutorPoolUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.concurrent.Executor;

/**
 * 描述:
 * @author Vic.xu
 * @date 2022-02-07 17:46
 */
public class XqdDispatcherServlet extends HttpServlet {

    private static Logger logger = LoggerFactory.getLogger(XqdDispatcherServlet.class);

    /**
     * 创建一个处理请求的线程池
     */
    Executor executor = ExecutorPoolUtils.createExecutor(20, this.getClass().getSimpleName());

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        logger.info("开始异步处理客户端请求");
        executor.execute(new XqdHttpServerHandlerRunnable(req, res));
    }

}
